//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Graphics/Primitives/Vertices.h"

namespace Engine
{
namespace Primitives
{

	//
	// Point Indices
	//

	template <gl_primitive::type PrimitiveType>
	struct PointIndices
	{
		static gl_primitive::type	Primitive ()
		{
			return PrimitiveType;
		}

		static uint IndexCount ()
		{
			return 1;
		}

		static void GetIndices (uint16 *idx, uint16 offset)
		{
			idx[0] = offset;
		}
	};



	//
	// Line Indices
	//

	struct LineIndices
	{
		static gl_primitive::type	Primitive ()
		{
			return gl_primitive::LINE;
		}

		static uint IndexCount ()
		{
			return 2;
		}

		static void GetIndices (uint16 *idx, uint16 offset)
		{
			idx[0] = offset + 0;
			idx[1] = offset + 1;
		}
	};



	//
	// Rectangle Indices
	//

	struct RectangleIndices
	{
		static gl_primitive::type	Primitive ()
		{
			return gl_primitive::TRIANGLE;
		}

		static uint IndexCount ()
		{
			return 6;
		}

		static void GetIndices (uint16 *idx, uint16 offset)
		{
			idx[0] = offset + 0;
			idx[1] = offset + 1;
			idx[2] = offset + 2;
			idx[3] = offset + 2;
			idx[4] = offset + 1;
			idx[5] = offset + 3;
		}
	};



	//
	// Batch Indices for 9 Rectangles 
	//
	
	struct NineRectIndices
	{
	// types
	protected:
		typedef static_array< uint16, 9*6 >		indices_t;


	// variables
	protected:
		indices_t	_indices;
		uint8		_indicesCount;


	// methods
	public:
		NineRectIndices () : _indicesCount(0)
		{}

		gl_primitive::type	Primitive () const
		{
			return gl_primitive::TRIANGLE;
		}

		uint IndexCount () const
		{
			return _indicesCount;
		}

		void GetIndices (uint16 *idx, uint16 offset) const
		{
			for (uint i = 0; i < _indicesCount; ++i)
			{
				idx[i] = _indices[ i + offset ];
			}
		}
	};


}	// Primitives
}	// Engine